﻿using Lhz.Sc.Business;
using Lhz.Sc.Entity.Database;
using Lhz.Sc.Entity.Enum;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;

namespace Lhz.Sc.Test
{
    [TestClass]
    public class UnitTestAddTestData
    {
        //[TestMethod]
        public void TestMethodAddTestData()
        {
            var so = new ServiceProxy();
            var ao = new ApplicationProxy();
            var authorizationOperation = new AuthorizationProxy();
            var lo = new LogProxy();
            var uo = new UserProxy();
            so.Delete(so.Query());
            ao.Delete(ao.Query());
            var a = authorizationOperation.Query();
            authorizationOperation.Delete(authorizationOperation.Query());
            lo.Delete(lo.Query());
            uo.Delete(uo.Query());
            uo.Add(new User()
            {
                Username = "admin",
                Password = "123",
                IsAdmin = true,
                Name = "管理员",
                Phone = "13514266786"
            });
            uo.Add(new User()
            {
                Username = "liuhongzhe",
                Password = "123",
                IsAdmin = false,
                Name = "劉宏哲",
                Phone = "13514266786"
            });
            uo.Add(new User()
            {
                Username = "wangmeina",
                Password = "123",
                IsAdmin = false,
                Name = "王美娜",
                Phone = "15840334266"
            });
            var applicationServiceCenter = new Application()
            {
                No = "Sc",
                Name = "服务中心",
                Description = "服务中心系统。"
            };
            ao.Add(applicationServiceCenter);
            var userService = new Service()
            {
                ApplicationGuid = applicationServiceCenter.Guid,
                Application = applicationServiceCenter,
                No = "user",
                Name = "用户服务",
                Url = "http://localhost:10000/ServiceUser.svc",
                Description = "用户服务。"
            };
            var applicationService = new Service()
            {
                ApplicationGuid = applicationServiceCenter.Guid,
                Application = applicationServiceCenter,
                No = "application",
                Name = "应用服务",
                Url = "http://localhost:10000/ServiceApplication.svc",
                Description = "应用服务。"
            };
            var serviceService = new Service()
            {
                ApplicationGuid = applicationServiceCenter.Guid,
                Application = applicationServiceCenter,
                No = "service",
                Name = "服务服务",
                Url = "http://localhost:10000/ServiceService.svc",
                Description = "服务服务。"
            };
            var operationService = new Service()
            {
                ApplicationGuid = applicationServiceCenter.Guid,
                Application = applicationServiceCenter,
                No = "operation",
                Name = "操作服务",
                Url = "http://localhost:10000/ServiceOperation.svc",
                Description = "服务服务。"
            };
            var authorizationService = new Service()
            {
                ApplicationGuid = applicationServiceCenter.Guid,
                Application = applicationServiceCenter,
                No = "authorization",
                Name = "授权服务",
                Url = "http://localhost:10000/ServiceAuthorization.svc",
                Description = "授权服务。"
            };
            var logService = new Service()
            {
                ApplicationGuid = applicationServiceCenter.Guid,
                Application = applicationServiceCenter,
                No = "log",
                Name = "日志服务",
                Url = "http://localhost:10000/ServiceLog.svc",
                Description = "日志服务。"
            };
            foreach (var service in new Service[] { userService, applicationService, serviceService, operationService, authorizationService, logService })
            {
                service.Operations = new List<Operation>();
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "query",
                    Name = "Query",
                    Description = "查询全部数据。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "queryByOrderBies",
                    Name = "QueryByOrderBies",
                    Description = "根据排序集合查询。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "queryByPagination",
                    Name = "QueryByPagination",
                    Description = "根据分页对象查询。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "queryByPaginationAndOrderBies",
                    Name = "QueryByPaginationAndOrderBies",
                    Description = "根据分页对象和排序集合查询。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "queryByPk",
                    Name = "QueryByPk",
                    Description = "根据主键查询数据。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "add",
                    Name = "Add",
                    Description = "添加单个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "adds",
                    Name = "Adds",
                    Description = "添加多个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "update",
                    Name = "Update",
                    Description = "更新单个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "updates",
                    Name = "Updates",
                    Description = "更新多个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "delete",
                    Name = "Delete",
                    Description = "删除单个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "deletes",
                    Name = "Deletes",
                    Description = "删除多个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "deleteByPk",
                    Name = "DeleteByPk",
                    Description = "根据主键删除单个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "deleteByPks",
                    Name = "DeleteByPks",
                    Description = "根据主键删除多个对象。"
                });
            }
            userService.Operations.Add(new Operation()
            {
                ServiceGuid = userService.Guid,
                Service = userService,
                No = "queryByUsernameAndPassword",
                Name = "QueryByUsernameAndPassword",
                Description = "根据用户名和密码查询用户。"
            });
            applicationService.Operations.Add(new Operation()
            {
                ServiceGuid = applicationService.Guid,
                Service = applicationService,
                No = "deleteCheck",
                Name = "DeleteCheck",
                Description = "检查指定主键的应用是否允许删除。"
            });
            serviceService.Operations.Add(new Operation()
            {
                ServiceGuid = serviceService.Guid,
                Service = serviceService,
                No = "queryByApplicationGuid",
                Name = "QueryByApplicationGuid",
                Description = "根据应用标识查询服务数据。"
            });
            serviceService.Operations.Add(new Operation()
            {
                ServiceGuid = serviceService.Guid,
                Service = serviceService,
                No = "queryByUserGuid",
                Name = "QueryByUserGuid",
                Description = "根据用户标识查询服务。"
            });
            operationService.Operations.Add(new Operation()
            {
                ServiceGuid = operationService.Guid,
                Service = operationService,
                No = "queryByUserGuidAndServiceGuid",
                Name = "QueryByUserGuidAndServiceGuid",
                Description = "根据用户标识和服务标识查询。"
            });
            authorizationService.Operations.Add(new Operation()
            {
                ServiceGuid = authorizationService.Guid,
                Service = authorizationService,
                No = "queryByUserGuid",
                Name = "QueryByUserGuid",
                Description = "根据用户标识查询授权数据。"
            });
            authorizationService.Operations.Add(new Operation()
            {
                ServiceGuid = authorizationService.Guid,
                Service = authorizationService,
                No = "deleteByUserGuid",
                Name = "DeleteByUserGuid",
                Description = "根据用户标识删除授权数据。"
            });
            so.Add(userService);
            so.Add(applicationService);
            so.Add(serviceService);
            so.Add(operationService);
            so.Add(authorizationService);
            so.Add(logService);
            foreach (var user in uo.Query())
            {
                authorizationOperation.Add(new Authorization()
                {
                    UserGuid = user.Guid,
                    AuthorizationType = AuthorizationType.ApplicationAuthorization,
                    ObjectGuid = applicationServiceCenter.Guid
                });
            }
        }

        //[TestMethod]
        public void TestMethodAddPpTestData()
        {
            TestMethodAddTestData();
            var so = new ServiceProxy();
            var ao = new ApplicationProxy();
            var authorizationOperation = new AuthorizationProxy();
            var lo = new LogProxy();
            var uo = new UserProxy();
            var user = new User()
            {
                Username = "ppuser",
                Password = "123",
                IsAdmin = false,
                Name = "权限平台用户",
                Phone = "18240090928"
            };
            uo.Add(user);
            var applicationPp = new Application()
            {
                No = "Pp",
                Name = "权限平台",
                Description = "权限平台服务。"
            };
            ao.Add(applicationPp);
            var serviceApplication = new Service()
            {
                ApplicationGuid = applicationPp.Guid,
                Application = applicationPp,
                No = "application",
                Name = "应用服务",
                Url = "http://localhost:12000/ServiceApplication.svc",
                Description = "应用服务。"
            };
            var serviceOrganization = new Service()
            {
                ApplicationGuid = applicationPp.Guid,
                Application = applicationPp,
                No = "organization",
                Name = "组织机构服务",
                Url = "http://localhost:12000/ServiceOrganization.svc",
                Description = "组织机构服务。"
            };
            var serviceRegion = new Service()
            {
                ApplicationGuid = applicationPp.Guid,
                Application = applicationPp,
                No = "region",
                Name = "区域服务",
                Url = "http://localhost:12000/ServiceRegion.svc",
                Description = "区域服务。"
            };
            var serviceRole = new Service()
            {
                ApplicationGuid = applicationPp.Guid,
                Application = applicationPp,
                No = "role",
                Name = "角色服务",
                Url = "http://localhost:12000/ServiceRole.svc",
                Description = "角色服务。"
            };
            var serviceUser = new Service()
            {
                ApplicationGuid = applicationPp.Guid,
                Application = applicationPp,
                No = "user",
                Name = "用户服务",
                Url = "http://localhost:12000/ServiceUser.svc",
                Description = "用户服务。"
            };
            foreach (var service in new Service[] { serviceApplication, serviceOrganization, serviceRegion, serviceRole, serviceUser })
            {
                service.Operations = new List<Operation>();
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "query",
                    Name = "Query",
                    Description = "查询全部数据。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "queryByOrderBies",
                    Name = "QueryByOrderBies",
                    Description = "根据排序集合查询。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "queryByPagination",
                    Name = "QueryByPagination",
                    Description = "根据分页对象查询。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "queryByPaginationAndOrderBies",
                    Name = "QueryByPaginationAndOrderBies",
                    Description = "根据分页对象和排序集合查询。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "queryByPk",
                    Name = "QueryByPk",
                    Description = "根据主键查询数据。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "add",
                    Name = "Add",
                    Description = "添加单个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "adds",
                    Name = "Adds",
                    Description = "添加多个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "update",
                    Name = "Update",
                    Description = "更新单个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "updates",
                    Name = "Updates",
                    Description = "更新多个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "delete",
                    Name = "Delete",
                    Description = "删除单个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "deletes",
                    Name = "Deletes",
                    Description = "删除多个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "deleteByPk",
                    Name = "DeleteByPk",
                    Description = "根据主键删除单个对象。"
                });
                service.Operations.Add(new Operation()
                {
                    ServiceGuid = service.Guid,
                    Service = service,
                    No = "deleteByPks",
                    Name = "DeleteByPks",
                    Description = "根据主键删除多个对象。"
                });
            }
            serviceUser.Operations.Add(new Operation()
            {
                ServiceGuid = serviceUser.Guid,
                Service = serviceUser,
                No = "queryByUsernameAndPassword",
                Name = "QueryByUsernameAndPassword",
                Description = "根据用户名和密码查询用户。"
            });
            so.Add(serviceApplication);
            so.Add(serviceOrganization);
            so.Add(serviceRegion);
            so.Add(serviceRole);
            so.Add(serviceUser);
            authorizationOperation.Add(new Authorization()
            {
                UserGuid = user.Guid,
                AuthorizationType = AuthorizationType.ApplicationAuthorization,
                ObjectGuid = applicationPp.Guid
            });
        }
    }
}
